﻿<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>CREE出货扫描</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="./_assets/css/custom.min.css">
  </head>
  <body >
  <div class="container"; style="position:relative; left:0px; top:0px; overflow:auto"; >
	<form id="myform">
	
	  <fieldset>
		<legend>CREE出货扫描</legend>
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">發貨單號:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="FA180504171" id="Order_id" type="text">
		  </div>
		</div>	
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">补充码:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="01/02" id="supplement" type="text">
		  </div>
		</div>	
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">铝箔袋入库:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="JK3030AWT-0-3G0-M20-BQ-H-01|26-Apr-2018|5000|1804260244" id="lv_storage" type="text">
		  </div>
		</div>	

		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">铝箔袋出库:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="JK3030AWT-00-0000-000B0HL250E|JK3030AWT-0-3G0-M20-BQ-H-01|1804260244|5000|26-Apr-2018|50117004668" id="lv_shipment" type="text">
		  </div>
		  <div class="col-sm-2">
			<input readonly="" class="form-control-plaintext" id="msg" value="" type="text">
		  </div>
		</div>	
		
		<div class="form-group row">
		  
		  <div class="col-sm-12">
		  <br>
		  </div>
		</div>

		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">Lot_ID:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="170808C001" id="Lot_ID" type="text">
		  </div>
		  <div class="col-sm-2">
			<input readonly="" class="form-control-plaintext" id="msg1" value="" type="text">
		  </div>
		</div>	
		
		<div class="form-group row">
		  <div class="col-sm-4">
			<p class="lead">
			<a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
			</p>
		  </div>
		  <div class="col-sm-4">
			<button type="button" id="btnNextbox" class="btn btn-primary">下一箱</button>
		  
		  </div>
		</div>	
		<div class="form-group row" id="my"></div>
		
		 <div class="row">
			<div class="col-md-12">
				<table class="table table-hover" id="dats_table">
					<thead>
						<tr>
							<th id="number">序号</th>
							<th>Bin</th>
							<th>Date</th>
							<th id="sumqty">Qty</th>
							<th>Lot_ID</th>
							<th>kit</th>
							<th>PO_Num</th>
						</tr>
				 	</thead>
				 	<tbody>
						
				 	</tbody>
				</table>
			</div>
		</div> 
	</form>	
	</div>
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	<script src="./jexcel-master/dist/js/jquery.jexcel.js"></script>
	<script src="./layui/layui.js"></script>
	<script>
	var disks;
	var idTd;
	var storage;
	var storages="";
	var Kit;
	var Plan_data ;
	var ss;
	var testlotID=0;//测试lotID是否重复
	var sumqty=0;
	var Order;
	var a = new Array();
	var b = new Array();
	var  disksnumber=0;
	layui.use(['layer','form','element'], function(){
		
		if (localStorage.name){
			//$("#YGXM").val(localStorage.name)
			console.log(localStorage.name);
			//console.log("员工信息: "+ localStorage.name);
		}
		
	});
	
		$("#Order_id").keypress(function(e){    //通過訂單號獲取bincode信息
		  var key = e.which;
		  
		  if (key == 13) {
		   a.splice(0,a.length);
		   console.log($("#supplement").val());
		   for(var i=0;i<a.length;i++){
				console.log(a[i]);
				a[i]=a[i].substring(0,a[i].length-2);
		   }
		   
		   
		  localStorage.name="";
			Order=$("#Order_id").val();
			console.log(Order);
				$.ajax({ 
					url: "getCREE_1.php?Order="+Order,//通过订单号查询
					dataType : "json",
					success: function(data){
					console.log(data);
						for(var i=0;i<data.length;i++){ 
							b[i]=data[i];//獲取匹配bincode所有解析碼
							b[i]=b[i].substring(0,b[i].length-2);//去除后面两位补充码
							console.log(b[i]);
							//alert(a[i]);
						}
					}
				});
				$("#supplement" ).select();
			}
		});
		$("#supplement").keypress(function(e){//手动输入后两位补充码
		  var key = e.which;
		  if (key == 13) {
			if($("#supplement").val()!=null){
		     $("#lv_storage" ).select();
			 }
			 else{
				layer.msg('补充码不能为空!');
			 }
		  }
		});			
		$("#lv_storage").keypress(function(e){    //
		  console.log($("#lv_storage").val());
		  var key = e.which;
		  if (key == 13) {
			$("#msg1").val("");
			storage = $("#lv_storage").val(); 
			storages=storage.split("|");
			var st = $("<td></td>").append("入库码");
			storageBin = $("<td id='"+'storageBin'+disksnumber+"'></td>").append(storages[0]);
			storageDate = $("<td id='"+'storageDate'+disksnumber+"'></td>").append(storages[1]);
			storageQty = $("<td id='"+'storageQty'+disksnumber+"'></td>").append(storages[2]);
			storageLot_ID = $("<td id='"+'storageLot_ID'+disksnumber+"'></td>").append(storages[3]);
			storageKit = $("<td></td>").append("");
			storagePO_Num = $("<td></td>").append("");
			/*$("<tr id='"+'storagetr'+disksnumber+"'></tr>")
				.append(st).append(storageBin).append(storageDate).append(storageQty).append(storageLot_ID).append(storageKit).append(storagePO_Num)
				.appendTo("#dats_table tbody ").insertBefore($("#dats_table tbody tr:first"));*/
			$("#msg").val("");
			$( "#lv_shipment" ).select();//光标选中
		 }
		});	
		
		$("#lv_shipment").keypress(function(e)
		{
		  console.log($("#lv_shipment").val());
		  var key = e.which;
		  var i;
		  var j;
		  var k=0;
		  if (key == 13) { 
			   var itemkit="";//item与kit验证结果
			   var shipment=$("#lv_shipment").val();
			   shipments=shipment.split("|");//切割出庫碼
			   
			   items=storages[0].split("-");
 			   items0=items[0];
			   items1=items[4].substring(0,1);
			   items2=items[5];
			   
			   kits=shipments[0].split("-");
			   kits0=kits[0];
			   kits1=kits[3].substring(3,4);
			   kits2=kits[3].substring(5,6);
			   
			   if(items0==kits0&&items1==kits1&&items2==kits2){
					itemkit="t";
			   }
			   
				console.log(shipment+"-"+shipments[1]);
			   for(i=0;i<storages.length;i++){//循环判断入库4个标签是否与出库匹配上
				for(j=0;j<shipments.length;j++){
					if(storages[i]==shipments[j]){
						k++;
						break;
					} 
				}
			  }
			    var st = $("<td></td>").append(disksnumber+1);
				var  shipmentBin = $("<td id='"+'shipmentBin'+disksnumber+"'></td>").append(shipments[1]);
				var  shipmentDate = $("<td id='"+'shipmentDate'+disksnumber+"'></td>").append(shipments[4]);
				var  shipmentQty = $("<td id='"+'shipmentQty'+disksnumber+"'></td>").append(shipments[3]);
				var  shipmentLot_ID = $("<td id='"+'shipmentLot_ID'+disksnumber+"'></td>").append(shipments[2]);
				var  shipmentKit = $("<td id='"+'shipmentKit'+disksnumber+"'></td>").append(shipments[0]);
				var  shipmentPONum = $("<td id='"+'shipmentPONum'+disksnumber+"'></td>").append(shipments[5]);
			
				Kit = shipments[0];
				$.ajax({ url: "getCREE.php?Str="+Kit,//验证Kit是否与数据库匹配
					dataType : "json",
					async: false,
					success: function(data){
						var i=0;
						Plan_data = data[8];//返回的第八位为kit
						console.log(data);
						var f='';
						if(k==4&&Plan_data==Kit){
						
							for(var j=0;j<a.length;j++){
								if(a[j]==shipments[2]){
									$("#lv_shipment").val("存在相同的lotID");
									testlotID=1;
								}
							}
						
							for(i=0;i<b.length;i++){
							//alert(b[i]);
							bin_2=shipments[1].substring(shipments[1].length-2,shipments[1].length);
							bin_2s=shipments[1].substring(0,shipments[1].length-2);
							console.log(b[i]+"--"+bin_2s+"--"+testlotID+"--"+$("#supplement").val()+"--"+itemkit)
								
								if(bin_2s==b[i]&&testlotID==0&&bin_2==$("#supplement").val()&&itemkit=="t"){
									$("<tr id='"+'shipmenttr'+disksnumber+"'></tr>")
									.append(st).append(shipmentBin).append(shipmentDate).append(shipmentQty).append(shipmentLot_ID).append(shipmentKit).append(shipmentPONum)
									.appendTo("#dats_table tbody ").insertBefore($("#dats_table tbody tr:first"));//将td放入tr内在放入tbody然后将整行置顶
									$("#msg").val("验证通过	").css('color','green');
									
									$("#lv_storage" ).select();
									
									a[disksnumber]=shipments[2];
									localStorage.name=a;//将lotID存在本地中
									
									disksnumber++;
									sumqty=sumqty+(parseInt(shipments[3]))/1000;
									$("#sumqty").html(sumqty);
									$("#number").html(disksnumber);
									f='ture';
									break;
								}
							}
							if(f!='ture'){
								$("#lv_storage" ).val("");
								$( "#lv_storage" ).select();
								$("#msg").val("數據庫未更新或驗證失敗").css('color','red');
							}
						
					   }
						else{
							$("#lv_storage" ).val("");
							$( "#lv_storage" ).select();
							$("#msg").val("验证失败").css('color','red');
						}
						testlotID=0;
					}
				});
		
			}
		  });	
	
		$("#Lot_ID").keypress(function(e){    //
			  console.log($("#Lot_ID").val());
			  var i;
			  var key = e.which;
			  var testID='f';
			  if (key == 13) {
				var Lot_ID=$("#Lot_ID").val();
				for(i=0;i<disksnumber;i++){
				var Lot_IDS=document.getElementById("shipmentLot_ID"+i).innerHTML;//获取出库标签上的Lot_ID值
				if(Lot_ID==Lot_IDS){
						$("#shipmenttr"+i).css('color','green').insertBefore($("#dats_table tbody tr:first"));//匹配成功后出库码整行变绿并置顶
						$("#msg1").val("匹配成功").css('color','green');
						testID='t';
						$( "#Lot_ID" ).select();
					}
					
				}
				 if(testID=='f'){
						$("#msg1").val("匹配失败").css('color','red');
						$("#Lot_ID" ).select();
					}
				}
			});
	
		$("#btnNextbox").click(function(){//点击按钮后将table清空并清空标记符
			$( "#lv_storage" ).select();
			$("#dats_table tbody").empty();
			$("#msg").val("");
			$("#Lot_ID" ).val("");
			$("#msg1").val("");
			$("#lv_shipment").val("");
			$("#sumqty").html("sumqty");
			$("#number").html("number");
			disksnumber=0;
			sumqty=0;
		});	
	</script>
  </body>
</html>